package com.yun.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.yun.pojo.Medical;
import com.yun.pojo.Pet;
import com.yun.pojo.db.Doctor;
import com.yun.pojo.db.Sickroom;
import com.yun.service.MedicalService;
import com.yun.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collection;
import java.util.List;

@Controller
public class MedicalController {

    @Autowired
    MedicalService medicalService;

    @Autowired
    PetService petService;

    @RequestMapping("/getMedical")
    public String getMedical(Model model) {
        List<Pet> pets = petService.queryPets();
        model.addAttribute("pets", pets);
        return "doctor/medical";
    }
    @RequestMapping("/toWork/{id}")
    public String toWork(@PathVariable("id") int id, Model model){
        Pet pet = petService.queryPetById(id);
        List<Medical> medicals = medicalService.getMedicals();
        model.addAttribute("pet",pet);
        model.addAttribute("medicals",medicals);
        return "doctor/work";
    }
    @RequestMapping("/medical")
    public String medical(Model model,Pet pet){
        medicalService.updateMedical(pet);
        List<Pet> pets = petService.queryPets();
        model.addAttribute("pets",pets);
        return "doctor/medical";
    }
    @RequestMapping("/over/{id}")
    public String over(@PathVariable("id")int id,Model model){
        petService.deleteById(id);
        List<Pet> pets = petService.queryPets();
        model.addAttribute("pets",pets);
        return "doctor/medical";
    }
}
